/**
   EMMA = Estación Meteorológica de Muestreo Automática
 
 emma_project
 Copyright (C) 2015  Rodrigo Garcia

 This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "sensors_flags.h"

void UpdateFlagsFromEEPROM(void)
{
  temperature_ctrl = EEPROM_read(TEMPERATURE_CTRL_BYTE1);
  relative_humidity_ctrl = EEPROM_read(RELATIVE_HUMIDITY_CTRL_BYTE1);
  // ..
}

void SetEEPROMFlag(unsigned char eeprom_addr, unsigned char bit)
{
  if(bit<8)
    EEPROM_write(eeprom_addr, (EEPROM_read(eeprom_addr)|(1<<bit)));
}

void ClearEEPROMFlag(unsigned char eeprom_addr, unsigned char bit)
{
  if(bit<7)
    EEPROM_write(eeprom_addr, (EEPROM_read(eeprom_addr) & ~(1<<bit)));
}

void SetRegister(unsigned char *reg, unsigned char flag)
{
  *reg |= 1<<flag;
}

void ClearRegister(unsigned char *reg, unsigned char flag)
{
  *reg &= ~(1<<flag);
}
